library(vegan) library(permute) library(cluster) library(pvclust) MVexp<-read.csv('MVexpress.csv'[,7:19], header=TRUE, row.names=3) MVgene<-MVexp[c(10:18)] #perform PCA using prcomp NOTE HERE: default for scale is FALSE, need to make scale=TRUE to use correlation matrix (correlation maxtrix NEEDS to be used if your variables are in different scales) MVgene.pca<-prcomp(MVgene,scale=TRUE) summary(MVgene.pca) pca.eigenval(MVgene.pca) screeplot(MVgene.pca, bstick=TRUE) ordi.monte(MVgene,ord='pca',dim=5) MVgene.pca$rotation pca.eigenvec(MVgene.pca,dim=5,digits=3,cutoff=.1) biplot(MVgene.pca) #more flexible and preferred approach, here choices are axes shown, type is the type of graph which may be points, text or none, display only sites or speces, the default for display is to show both, xlim and ylim (min,max) of the plot, then labels is optional text used for labels ordiplot(MVgene.pca,choices=c(1,2),type='text', display='sites',xlab="PC 1 (41%)", ylab="PC 2 (15%)") #next add the eigenvectors (i.e. variable loadings) #first add the arrows (multiply them by 5 so you can see them) arrows(0,0,MVgene.pca$rotation[,1]*5,MVgene.pca$rotation[,2]*5,col='purple') #then we added the text labels text(MVgene.pca$rotation[,1]*5.2,MVgene.pca$rotation[,2]*5.2,row.names(MVgene.pca$rotation)) #trying heat map cluster thing #ok, it worked with this template, so now I'm going to try pulling in all the genes. log transforming the data. saving the file as a txt file. then changing to a dat #logtransform MVlog<-data.trans(MVgene,method='log',plot=F) #transpose MVlogt<-t(MVlog) mat=data.matrix(MVlogt) library(RColorBrewer) library(gplots) pdf("MVlogtheatmap.pdf", height=10, width=10) heatmap.2(mat, Rowv=TRUE, Colv=TRUE, # dendrogram= c("none"), distfun = dist, hclustfun = hclust, xlab = "X data", ylab = "Y data", key=TRUE, keysize=1, trace="none", density.info=c("none"), margins=c(10, 8), col=brewer.pal(10,"PiYG") # col=redgreen(75), ) dev.off() #trying again to do within a timepoint MVexp<-read.csv('MVexpress.csv', header=TRUE, row.names=3) MVgene2<-MVexp[1:24,10:18] #perform PCA using prcomp NOTE HERE: default for scale is FALSE, need to make scale=TRUE to use correlation matrix (correlation maxtrix NEEDS to be used if your variables are in different scales) MVgene2.pca<-prcomp(MVgene,scale=TRUE) summary(MVgene2.pca) pca.eigenval(MVgene2.pca) screeplot(MVgene2.pca, bstick=TRUE) ordi.monte(MVgene2,ord='pca',dim=5) MVgene2.pca$rotation pca.eigenvec(MVgene2.pca,dim=5,digits=3,cutoff=.1) biplot(MVgene2.pca) #more flexible and preferred approach, here choices are axes shown, type is the type of graph which may be points, text or none, display only sites or speces, the default for display is to show both, xlim and ylim (min,max) of the plot, then labels is optional text used for labels ordiplot(MVgene2.pca,choices=c(1,2),type='text', display='sites',xlab="PC 1 (41%)", ylab="PC 2 (15%)") #next add the eigenvectors (i.e. variable loadings) #first add the arrows (multiply them by 5 so you can see them) arrows(0,0,MVgene2.pca$rotation[,1]*5,MVgene2.pca$rotation[,2]*5,col='purple') #then we added the text labels text(MVgene2.pca$rotation[,1]*5.2,MVgene2.pca$rotation[,2]*5.2,row.names(MVgene2.pca$rotation)) ?ordiplot ?identify.ordiplot